#ifndef __PROJECT_H__
#define __PROJECT_H__

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#define MSGPATH "/home"
#define MSGSIZE (sizeof(Msg_t) - sizeof(long))


key_t key;
int msqid;

pthread_t tid;
pthread_t env_tid;
pthread_t limit_tid;
pthread_t dev_tid;
pthread_t beep_tid;


/*定义当前环境数据变量空间*/
float con_temp;  // 全局变量-
unsigned char con_hume;
unsigned short con_iull;
float global_wendu;
float global_shidu;

int spi_fla;  // 0 会显示东西  1 不会显示东西   
volatile int beep_fla;

char con_led;
char con_beep;
char con_fan;
/*定义阈值参考变量空间*/
float limit_t_up;
float limit_t_down;
unsigned char limit_h_up;
unsigned char limit_h_down;
unsigned short limit_i_up;
unsigned short limit_i_down;


// 环境
typedef struct{
	float temp;   // 温度
	float hume;   // 湿度
	unsigned short iull;
	char led_state;
	char beep_state;
	char fan_state;
} Env_t;

typedef struct
{
    float temp_up;
    float temp_down;
    float hume_up;
    float hume_down;
    float iull_up;
    float iull_down;
} Limit_t;


typedef struct{
	char led;
	char beep;
	char fan;
} Detctrl_t;

typedef struct msgbuf {
	long mtype; /* message type, must be > 0 */
	/*环境数据结构*/
	Env_t env;
	/*阈值设置结构*/
	Limit_t limit;
	/*设备控制结构*/
	Detctrl_t dev;

} Msg_t;

Msg_t msg;
Msg_t env_msg;
Msg_t limit_msg;
Msg_t dev_msg;

/*读取消息线程*/
void *msgget_thread(void *argv);

/*环境信息线程*/
void *env_thread(void *argv);

/*阈值设置线程*/
void *limit_thread(void *argv);

/*设备控制线程*/
void *dev_thread(void *argv);

/*蜂鸣器线程*/
void *beep_thread(void *argv);

/*设备初始化*/
int dev_init(void);

/*消息队列初始化*/
int msgqueue_init(void);

/*线程初始化*/
int thread_init(void);

void *led_thread(void *argv);

#endif
